﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "mystudio.h"
#include "MyGrid.h"
#include "MyMainRole.h"
#include <QFileDialog>
#include <QLabel>
#include <QRectF>

#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow() override;

private slots:
    void on_actionStart_triggered();

    void on_actionUndo_triggered();

protected:
    void timerEvent(QTimerEvent* event) override;
    void keyPressEvent(QKeyEvent *event) override;
//    void keyReleaseEvent(QKeyEvent* event) override;

private:
    Ui::MainWindow *ui;
    QGraphicsScene* scene;
    QGraphicsView* view;
    void initUi(int grids);

    double hasScaled = 1.0;
    qreal mWidth;
    int gridNumbers = 0;

    QRect displayRect;

    //是否开始运行
    bool isStart = false;
    //按键是否按下
    bool isPress = false;
    //按键时间
    int PressTime = 0;

    //目录
    QString filePath;
    QLabel* fileLabel;

    //底层图形矩阵
    QVector<QVector<MyGrid*>> vectorGround;
    MyMainRole* mRole = nullptr;
    QList<MyMainRole*> listRole;

    //定时器
    int timerId;
    //边框尺寸
    QSize saveSize;

    //检查指定位置的角色是什么内容
    int getRoleByPoint(QPoint poi);
    //角色移动到格子
    void moveRole(QPoint RolePoi,QPoint toPoi);

    //撤销列表
    QList<oneUndoOperate> undoLists;

};

#endif // MAINWINDOW_H
